/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zyyoona7.wheelpicker;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

/**
 * test
 *
 * @author rpf
 * @since 2021-05-25
 */
public class ExampleOhosTest {
    /**
     * 包名test
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.zyyoona7.wheelpicker", actualBundleName);
    }

    /**
     * 初始化及解析数据test
     */
    @Test
    public void initData(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method initData = mainAbilitySlice.getMethod("initData");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            initData.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    /**
     * 音效test
     */
    @Test
    public void turnOnSound(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method turnOnSound = mainAbilitySlice.getMethod("turnOnSound");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            turnOnSound.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 设置音量test
     */
    @Test
    public void setSoundEffect(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method setSoundEffect = mainAbilitySlice.getMethod("setSoundEffect");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            setSoundEffect.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 滚动效果test
     */
    @Test
    public void turnOnCyclic(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method turnOnCyclic = mainAbilitySlice.getMethod("turnOnCyclic");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            turnOnCyclic.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 滚动随机下标test
     */
    @Test
    public void setRandom(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method setRandom = mainAbilitySlice.getMethod("setRandom");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            setRandom.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 单选test
     */
    @Test
    public void drawCheckBox(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method drawCheckBox = mainAbilitySlice.getMethod("drawCheckBox");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            drawCheckBox.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 多选test
     */
    @Test
    public void drawCheckBox2(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method drawCheckBox2 = mainAbilitySlice.getMethod("drawCheckBox2");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            drawCheckBox2.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * 设置对齐test
     */
    @Test
    public void setAlign(){
        try {
            Class mainAbilitySlice = Class.forName("com.glidebitmappoolsample.slice.MainAbilitySlice");
            Method setAlign = mainAbilitySlice.getMethod("setAlign");
            Object object = mainAbilitySlice.getConstructor().newInstance();
            setAlign.invoke(object);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}